package com.ym.util;

import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;

import java.util.stream.Collectors;

public class BindingErrorUtil {
    public static String getError(BindingResult bindingResult) {
        return bindingResult.getFieldErrors().stream()
                .collect(Collectors.groupingBy(FieldError::getField)) // 按字段分组
                .entrySet().stream()
                .map(entry -> entry.getKey() + " : " + entry.getValue().stream().map(FieldError::getDefaultMessage).collect(Collectors.joining(" , ")))
                .collect(Collectors.joining(" ; "));
    }
}
